/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.fee.core.repository.service;

import cn.hutool.core.util.ObjectUtil;
import info.peigen.hotpot.business.fee.core.domain.FeeLog;
import info.peigen.hotpot.business.fee.core.domain.action.FeeConverter;
import info.peigen.hotpot.business.fee.core.repository.entity.FeeLogEntity;
import info.peigen.hotpot.business.fee.core.repository.mapper.FeeLogMapper;
import info.peigen.hotpot.component.data.repository.beetlsql.service.AbstractBeetlSqlRepository;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.FieldDefaults;
import org.noear.solon.annotation.Component;

/**
 * <b>(FeeLogRepository)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/8/5
 */
@Data
@EqualsAndHashCode(callSuper = true)
@FieldDefaults(level = AccessLevel.PRIVATE)
@Component
public class FeeLogRepository extends AbstractBeetlSqlRepository<FeeLogMapper, FeeLogEntity> {
    public void store(FeeLog domain) {
        FeeLogEntity entity = FeeConverter.convertFeeLog(domain);
        if (ObjectUtil.isNotNull(domain.getAccount())) {
            entity.setAccountId(domain.getAccount().getAccountId());
        }
        entity.setFeeCurrency(domain.getFeeAmount().getCurrency());
        entity.setPayeeAccountId(domain.getPayeeAccount() != null ? domain.getPayeeAccount().getAccountId() : null);
        saveOrUpdate(entity);
    }
}